abstract class Tree[+T] {
  def leaf: Int
}

case class Node[+T](entry: T, l: Tree[T], r: Tree[T]) extends Tree[T] {
  def leaf: Int = (l, r) match {
    case (End, End) => 1
    case _          => l.leaf + r.leaf
  }
}

case object End extends Tree[Nothing] {
  def leaf: Int = 0
}